#!/usr/bin/env python
# -*- coding: utf-8 -*-
#code:utf-8
#
# Copyright(C) 2011 SupDo.com
# Licensed under the GUN License, Version 3.0 (the "License");
# 
# File:        models
# Author:      KuKei
# Create Date: 2011-04-18
# Description: 模型目录
# Modify Date: 2011-04-18

from django.db import models

#模型基类
class BaseModel(models.Model):         
    def initData(self, formsData):
        #模型中不存在的字段，不能作为入常
        fields = {}
        for field in iter(self._meta.fields):
            if formsData.has_key(field.attname):
                fields[field.attname] = formsData[field.attname]
        #这种方法优雅，但是args为空，可能造成造成漏洞，暂且不用这种方法
        #经确定，此方法可行，正常赋值时args就为空
        apply(models.Model.__init__, (self,), fields)
        return self
    
    def updateData(self, formsData):
        for field in iter(self._meta.fields):
            if formsData.has_key(field.attname):
                self.__setattr__(field.attname, formsData[field.attname])
        return self
    
    def initOptions(self, name, listValue):
        try:
            self._meta._name_map[name][0].choices = listValue
        except Exception, ex:
            pass
        return self
    
    class Meta:
        #Meta中的abstract属性表明此类为抽象类，可以做基类；
        abstract = True
        #app_label是为了表明此类为app的模型，以便生成sql语句
        #这样的取值方法是因为django对模板文件夹的位置有要求
        app_label = __name__.split('.')[-2]
        
#导入具体模型信息
from sd.cms.models.userModel import * 
from sd.cms.models.paramModel import * 
from sd.cms.models.appModel import * 